﻿<!DOCTYPE HTML>
<html>
	<head>
		<title>Bddify Test Result @DateTime.Now.ToShortDateString()</title>
		
		<style type="text/css">
			body
			{
				min-width:900px;
				max-width:100%;
				background-color:#fff;
				font-family: Verdana, Arial, Helvetica, sans-serif;
				font-size: 10pt;
				margin: 0;
				padding: 0;
				min-height:700px;
				background-repeat: repeat-x;
		    background-image: url();			}

      li
      {
        list-style-type: none;
      }
			
			#main
			{
				width: 100%;
				height:100%;
			}
			
			#header
			{
				vertical-align:middle;
				padding:10px;
				background-repeat: repeat-x;
				background-image: url();
        border-bottom: 2px solid #fff;
        height: 57px;
			}
			
			#footer
			{
			  color:#fff;
				background-repeat: repeat-x;
				background-image: url();			  padding-top:15px;
			  padding-bottom:15px;
			  margin-top:20px;
			  text-align:center;
			}
			
			#footer a
			{
			  color:#fff;
			}
			
			#footer a:hover
			{
			  color:#3865C6;
			}
			
			#bddifyTitle
			{
			  	font-size: 20pt;
			  	font-family: Trebuchet MS;
			  	font-weight:bold;
				  color: white;
				  text-shadow: #262f57 1px 1px 3px;
			}
			
			#bddifyDescription
			{
			  font-size:large;
				color:#fff;
				color: #fff;
				text-shadow: #262f57 1px 1px 3px;
			}
			
			#summaryDiv
			{
			  margin:5px;
			  padding:5px;
			}

      div#generatedAt
      {
        font-size: 12pt;
        font-family:Cambria;
        color:#229;
      }			
						
			#coverageSummary
			{
				margin-left:50px;
			}
 
			#testResult
			{
			  margin:5px;
			  padding:5px;
			}

			#testResult p 
			{
			    font-weight: bold;
			    color: #2B547D;
			    font-size: 12pt;
			}

			#testResult span
			{
			    color: #2B547D;
			    margin-left:5px;
			    margin-top:20px;
			    margin-bottom:20px;
			    font-size: 10pt;
			}
			
			#testResult>table
			{
		        background-color:White;
		        color:Black;
			}
			
			table
			{
				  width:100%;
				  padding:5px;
				  border-collapse: collapse;
			}
			
			tbody
			{
				text-align:left;
			}
			
			td 
			{
				padding:5px;
				border-right: 0;
			  border: 1px solid #f0f0f0;
			}

      tr.step td
      {
        border:0px;
      }
			
			td.Passed
			{
				background-color: #a9e088;				background-image: url();
				background-repeat: no-repeat;		    background-position: center center;
			}
			
			td.Failed
			{
				background-color: #f7b8ad;
				font-weight:bold;				background-repeat: no-repeat;		    background-position: center center;		    background-image: url();
			}
			
			td.Inconclusive
			{
				background-color: #fff8b9;				background-repeat: no-repeat;		    background-position: center center;		    background-image: url();
			}
			
			td.NotImplemented
			{
				background-color: #c7e3ff;
			  background-repeat: no-repeat;		    background-position: center center;		    background-image: url();			}
			
			td.NotExecuted
			{
				background-color:#c7e3ff;
				background-repeat: no-repeat;		    background-position: center center;		    background-image: url();			}
			
			td.FailedException
			{
				font-weight: bold;
				color: Maroon;
			}
			
			td.NotImplementedException
			{
			  font-weight:bold;
			}
			
			td.InconclusiveException
			{
			  font-weight:bold;
			}
			
			tr.scenario
			{
				cursor:pointer;
			}
			
			td.scenarioText
			{
				color: #000;
			}
			
			td.namespaceResultSummary
			{
			  width:20%;
			}
			
			tr.namespaceResultSummary
			{
			    height:17px;
			}
			
			th.scenarioHeader
			{
				width:250px    
			}
 
			th.resultHeader
			{
				width:100px;
			}
			
			th.summaryHeader
			{
				width:100px;    
			}
			
			th.summaryCount
			{
				width:100px;    
			}
 
			td.duration
			{
				width:100px;
			}
			
			td.indentation
			{
				width: 0px;
				display: none;
			}
			
			td.result
			{
				width:150px;
			}
			
			table.summaryTable
			{
				width:200px;
				border-collapse:collapse;
			}
			
			table.summaryTable td
			{
				text-align:left;
			}
			
			.summaryLable
			{
			  width:120px;
			}
			
			tr.assembly
			{
				background-color:#101010;
				color:White;
				height:40px;
			}
			
			tr.namespace
			{
			  background: #f0f0f0;
			}
			
			tr.story
			{
			  background: #f0f0f0;
			  margin-bottom:0px;
      }
      
      ul.storyNarrative
      {
        font-style:italic;
        font-weight:bold;
        margin: 0px 0px 0px 20px;
        padding-top: 0px;
        color: #122F4B;
      }
			
			table.namespace
			{
			    font-weight: bold;
			}
			
			table.story
			{
			    font-weight: bold;
			}
			
			tr.step
			{
			  background-color:#fafafa;
			}
 
		  td.result
		  {
		    width:10px;
		  }
			
			#summaryDiv h4 
			{
			  font-size: 14pt;
			  color: #2B547D;
			}		
		</style>

		<script type="text/javascript">
		    function toggle(id) {
		      var e = document.getElementById(id);
		      if (e.style.display == 'none') {
		        e.style.display = '';
		      }
		      else {
		        e.style.display = 'none';
		      }
		    }
		</script>
	</head>

	<body>
		<div id="main">
			<div id="header">
				<span id="bddifyTitle">bddify</span>
                <br />
				<span id="bddifyDescription">A simple BDD framework for .Net developers</span>
			</div>

			<div id="summaryDiv">
        <h4>Summary</h4>
          
        @{
          var scenarios = Model.SelectMany(s => s.Scenarios).ToList();
          }
        <div id="innderSummaryDiv">
            <div id="resultSummary">
				      <table class="summaryTable">
					      <tbody>
						      <tr class="namespace">
                    <td />
							      <td class="summaryLable">Namespaces</td>
							      <td>@Model.Where(b => b.MetaData == null).SelectMany(s => s.Scenarios).GroupBy(b => b.TestObject.GetType().Namespace).Count()</td>
						      </tr>
						      <tr class="story">
                    <td />
							      <td class="summaryLable">Stories</td>
							      <td>@Model.Where(b => b.MetaData != null).GroupBy(b => b.MetaData.Type).Count()</td>
						      </tr>
						      <tr>
                    <td class="result Passed"></td>
                    <td class="summaryLable">Passed</td>
							      <td>@scenarios.Count(b => b.Result == Bddify.Core.StepExecutionResult.Passed)</td>
						      </tr>
						      <tr>
				            <td class="result Failed"></td>
							      <td class="summaryLable">Failed</td>
							      <td>@scenarios.Count(b => b.Result == Bddify.Core.StepExecutionResult.Failed)</td>
						      </tr>
						      <tr>
				            <td class="result Inconclusive"></td>
							      <td class="summaryLable">Inconclusive</td>
							      <td>@scenarios.Count(b => b.Result == Bddify.Core.StepExecutionResult.Inconclusive)</td>
						      </tr>
						      <tr>
				            <td class="result NotImplemented"></td>
							      <td class="summaryLable">Not Implemented</td>
							      <td>@scenarios.Count(b => b.Result == Bddify.Core.StepExecutionResult.NotImplemented)</td>
  					      </tr>
						      <tr>
				            <td class="result NotExecuted"></td>
							      <td class="summaryLable">Not Executed</td>
							      <td>@scenarios.Count(b => b.Result == Bddify.Core.StepExecutionResult.NotExecuted)</td>
						      </tr>
					      </tbody>
				      </table>
            </div>
        </div>
		  </div>

			<div id="testResult">
        @{
          string assemblyName = string.Empty;
          if (Model.Count > 0)
          {
            var scenario = Model.SelectMany(s => s.Scenarios).FirstOrDefault();
            if (scenario != null)
            {
              var codeBase = scenario.TestObject.GetType().Assembly.CodeBase;
              var uri = new UriBuilder(codeBase);
              assemblyName = Uri.UnescapeDataString(uri.Path);
            }
          }
        }

        <p>Assembly: '@assemblyName'</p>

				<table>
					<tbody>
          @{
            var groupedByNamespace = from story in Model
                                     where story.MetaData == null
                                     group story by story.Scenarios.First().TestObject.GetType().Namespace into g
                                     select g;

            var groupedByStories = from story in Model
                                   where story.MetaData != null
                                   group story by story.MetaData.Type.Name into g
                                   select g;

            var groupedScenarios = groupedByStories.Union(groupedByNamespace);

            foreach (var scenarioGroup in groupedScenarios)
            {
              var story = scenarioGroup.First();
              var scenariosInGroup = scenarioGroup.SelectMany(s => s.Scenarios);
              var headerClass = story.MetaData == null ? "namespace" : "story";
          		<tr class="@headerClass">
								<td colspan="5">
                  <table class="@headerClass">
                    <tr>
                    @if (story.MetaData == null)
                    {
                      <td>Namespace: @story.Scenarios.First().TestObject.GetType().Namespace</td>
                    }
                    else
                    {
                      <td>Story: @story.MetaData.Title</td>
                    }
                      <td class="namespaceResultSummary">

                    @if (story.Scenarios.Any())
                    {
                      var fullWidth = 400;
                      var all = scenariosInGroup.Count();
                      var failed = scenariosInGroup.Count(r => r.Result == Bddify.Core.StepExecutionResult.Failed);
                      var failedRatio = (double)failed / all * 100;
                      var failedVisible = (failedRatio == 0 ? "none" : "");
                      var passed = scenariosInGroup.Count(r => r.Result == Bddify.Core.StepExecutionResult.Passed);
                      var passedRatio = (double)passed / all * 100;
                      var passedVisible = (passedRatio == 0 ? "none" : "");
                      var notImplemented = scenariosInGroup.Count(r => r.Result == Bddify.Core.StepExecutionResult.NotImplemented);
                      var notImplementedRatio = (double)notImplemented / all * 100;
                      var notImplementedVisible = (notImplementedRatio == 0 ? "none" : "");
                      var inconclusive = scenariosInGroup.Count(r => r.Result == Bddify.Core.StepExecutionResult.Inconclusive);
                      var inconclusiveRatio = (double)inconclusive / all * 100;
                      var inconclusiveVisible = (inconclusiveRatio == 0 ? "none" : "");
                      var notExecuted = scenariosInGroup.Count(r => r.Result == Bddify.Core.StepExecutionResult.NotExecuted);
                      var notExecutedRatio = (double)notExecuted / all * 100;
                      var notExecutedVisible = (notExecutedRatio == 0 ? "none" : "");
                        <table>
                          <tr class="namespaceResultSummary">
                            <td class="Failed" style="width:@failedRatio%;display:@failedVisible"></td>
                            <td class="Passed" style="width:@passedRatio%;display:@passedVisible"></td>
                            <td class="NotImplemented" style="width:@notImplementedRatio%;display:@notImplementedVisible"></td>
                            <td class="Inconclusive" style="width:@inconclusiveRatio%;display:@inconclusiveVisible"></td>
                            <td class="NotExecuted" style="width:@notExecutedRatio%;display:@notExecutedVisible"></td>
                          </tr>
                        </table>
                      }
                      </td>
                    </tr>
                  </table>
                </td>
							</tr>
            
                  if (story.MetaData != null && !string.IsNullOrEmpty(story.MetaData.AsA))
                  { 
            <tr class="story">
              <td colspan="5">
                <ul class="storyNarrative">
                  <li>@story.MetaData.AsA </li>
                  <li>@story.MetaData.IWant </li>
                  <li>@story.MetaData.SoThat</li>
                </ul>
              </td>                                    
            </tr>
                  }

                  foreach (var scenario in scenariosInGroup)
                  { 
              <tr class="scenario" onclick="toggle('@scenario.Id');">
								<td class="result @scenario.Result"></td>
								<td class="scenarioText" colspan="3">@scenario.ScenarioText</td>
							</tr>
							<tr class="step" id="@scenario.Id" style="display:none">
                <td class="result" />
                <td colspan="3" style="padding:0px">
                  <table>
                  @foreach (var step in scenario.Steps.Where(s => s.ShouldReport))
                  {
                    string stepClass = string.Empty;
                    string result = step.ReadableMethodName.Replace(" ", "&nbsp;");
                    var rowSpan = 1;
                    if (step.Exception != null)
                    {
                      stepClass = step.Result + "Exception";
                      rowSpan = 2;

                      if (!string.IsNullOrEmpty(step.Exception.Message))
                      {
                        result += " [Exception Message: '" + step.Exception.Message + "']";
                      }
                    }
                    <tr class="step" onclick="toggle('@step.Id');">
    									<td rowspan="@rowSpan" class="result @step.Result"></td>
										  <td class="indentation"></td>
										  <td colspan="2" class="@stepClass">@result</td>
                    </tr>

                                          if (step.Exception != null)
                                          {
									  <tr class="step" id="@step.Id">
    									<td></td>
										  <td colspan="2" class="indentation"></td>
										  <td class="@stepClass"><code>@step.Exception.StackTrace</code></td>
									  </tr>
                                          }
                  }
                  </table>                                    
                </td>
		  				</tr>
                  }
            }
            }
					</tbody>
				</table>

        <p><span>Tested at: @DateTime.Now</span></p>
			</div>
		</div>

    <div id="footer">Powered by <a href="https://code.google.com/p/bddify/">bddify</a> framework</div>
	</body>
</html>